<?
/*! \brief Supplies different logging mechanisms. 
 * 
 */
class GenericLogger extends Zend_Log
{	
	public function __construct($type='')
	{
		parent::__construct();
		
		switch(strtoupper($type))
		{
			case 'FILE':
				$writer = $this->getStreamWriter(BASE_DIR.
					'/tmp/log/openbt.log');
				break;
			case 'DB':
				$table = Zend_Registry::get('db')->logtable;
				$writer = Zend_Log_Writer_Db($db, $table);
				break;
			case 'FIREBUG':
				$writer = new Zend_Log_Writer_Firebug();
				break;
			default:
				$writer = $this->getStreamWriter('php://output');	
				break;	
		}

		$this->addWriter($writer);
	}
	
	private function getStreamWriter($location)
	{
		try
		{
			$writer = new Zend_Log_Writer_Stream($location);
		}
		catch(Exception $e)
		{
			$writer = new Zend_Log_Writer_Stream('php://output');	
		}
		
		$format = '%timestamp% %priorityName% ['.getmypid().']: %message%' . PHP_EOL;
		$formatter = new Zend_Log_Formatter_Simple($format);
		$writer->setFormatter($formatter);
		
		return $writer;
	}
}